import math

from catboost import Pool, CatBoostRegressor
from sklearn.model_selection import train_test_split
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from sklearn.multioutput import MultiOutputRegressor
from sklearn.metrics import mean_squared_error
from sklearn.metrics import mean_absolute_error
from sklearn.metrics import mean_absolute_percentage_error, adjusted_rand_score
from catboost import Pool, cv

from src.python.util.getResoures import getData


def run():
    # 获取数据
    x_train, x_test, y_train, y_test = getData()
    # 定义CatBoost回归预测模型
    catBoost = CatBoostRegressor(
                                    iterations=400  # 最大迭代数
                                    , learning_rate=0.05  # 学习率
                                    , depth=10  # 最大深度
                                    , loss_function='RMSE'  # 损失函数
                                    , random_seed=6  # 随机数种子
                                    , verbose=0  # 不输出迭代信息
                                    , task_type="GPU" # 开启GPU运算
                                )
    # 转化为多标签回归模型
    model = MultiOutputRegressor(catBoost)
    # 训练
    print("------------------------------------------- CatBoost回归预测模型：-------------------------------------------")
    model.fit(x_train, y_train)
    y_pre = model.predict(x_test)
    # 评估分数
    mae = mean_absolute_error(y_pred=y_pre, y_true=y_test)
    print("平均绝对误差MAE:", mae)
    mse = mean_squared_error(y_pred=y_pre, y_true=y_test)
    print("均方根误差RMSE:", math.sqrt(mse))
    print("均方误差MSE:", mse)
    mape = mean_absolute_percentage_error(y_pred=y_pre, y_true=y_test)
    print("平均绝对百分比误差MAPE:", mape)


if __name__ == "__main__":
    run()
